const DATA_BASE = "https://api-hmugo-web.itheima.net/api/public/v1";
let ajaxTimes = 0;
export const myRequest = (options) => {
	ajaxTimes++;
	uni.showLoading({
		title:"加载中"
	})
	return new Promise((resolve,reject) => {
		uni.request({
			url:DATA_BASE+options.url,
			method:options.method || "get",
			data: options.data || {},
			success: (res) => {
				if(res.data.meta.status !== 200){
					return uni.showToast({
						title:"获取数据失败",
						icon:"none"
					})
				}
				resolve(res.data.message)
			},
			fail: (err) => {
				return uni.showToast({
					title:"请求接口失败",
					icon:"none"
				})
				reject(err)
			},
			complete:()=>{
				ajaxTimes--;
				if(ajaxTimes === 0){
					uni.hideLoading()
				}
			}
		})
	})
}